/*
 * Copyrignt (c) qkier.com. All Rights Reserved.
 * Author: xuzeshui@qkier.com
 * Created Time: 2017-04-21 14:03:41
 * Last Modified: 2017-04-21 14:07:25
 * File Name: db/openapi.go
 * Description:
 */

//
package db

import (
	"doubimeizhi.com/utility"

	"github.com/astaxie/beego"
	log "github.com/cihub/seelog"
)

var (
	openapiMySQLHelper *utility.MySQLHelper
)

func createOpenapiMySQLHelper() {
	mysqlHost := beego.AppConfig.DefaultString("cr::mysql_host", "10.10.1.24")
	mysqlPort := beego.AppConfig.DefaultInt("cr::mysql_port", 4108)
	mysqlUser := beego.AppConfig.DefaultString("cr::mysql_user", "openapi_w")
	mysqlPass := beego.AppConfig.DefaultString("cr::mysql_pass", "open123456")
	mysqlDB := beego.AppConfig.DefaultString("cr::mysql_db", "openapi")
	maxOpenConns := beego.AppConfig.DefaultInt("cr::mysql_max_open_conns", 10)
	maxIdleConns := beego.AppConfig.DefaultInt("cr::mysql_max_idle_conns", 2)
	log.Infof("mysql -h%s -P%d -u%s -p%s -D%s", mysqlHost, mysqlPort, mysqlUser, mysqlPass, mysqlDB)
	openapiMySQLHelper = utility.NewMySQLHelper(mysqlHost, mysqlPort, mysqlUser, mysqlPass, mysqlDB, maxOpenConns, maxIdleConns)
}

func GetOpenapiMySQLHelper() *utility.MySQLHelper {
	if openapiMySQLHelper == nil {
		createOpenapiMySQLHelper()
	}
	return openapiMySQLHelper
}

func init() {
	GetOpenapiMySQLHelper()
}
